package com.corechina.apex_osswords.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.corechina.apex_osswords.common.Response;
import com.corechina.apex_osswords.common.ShiroUtils;
import com.corechina.apex_osswords.common.SysLog;
import com.corechina.apex_osswords.domain.entity.SysCase;
import com.corechina.apex_osswords.service.ISysCaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 案例表 前端控制器
 * </p>
 *
 * @author cc
 * @since 2022-04-25
 */
@Api(tags = "案例配置")
@RestController
@RequestMapping("/sys/case")
public class SysCaseController {

    @Autowired
    private ISysCaseService iSysCaseService;

    @ApiOperation("新增")
    @SysLog("新增案例")
    @PostMapping("/add")
    public Response add(@RequestBody SysCase sysCase) {
        sysCase.setGroupId(ShiroUtils.getGroupId());
        iSysCaseService.save(sysCase);
        return Response.ok();
    }

    @ApiOperation("编辑")
    @SysLog("编辑案例")
    @PutMapping("/update")
    public Response update(@RequestBody SysCase sysCase) {
        iSysCaseService.updateById(sysCase);
        return Response.ok();
    }

    @ApiOperation("删除")
    @SysLog("删除案例")
    @DeleteMapping("/del")
    public Response del(Integer id) {
        iSysCaseService.removeById(id);
        return Response.ok();
    }

    @ApiOperation("详情")
    @GetMapping("/getOne")
    public Response getOne(Integer id) {
        return Response.ok(iSysCaseService.getById(id));
    }

    @ApiOperation("列表")
    @GetMapping("/getList")
    public Response getList(Integer pageIndex, Integer pageSize) {
        Page<SysCase> page = new Page<>(pageIndex, pageSize);
        iSysCaseService.page(page);
        return Response.ok(page.getRecords(), page.getTotal());
    }
}

